using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;
using XBLib.Dal.AdoDal;
using DataInfo;

using KenLib.Common;
namespace KenLib.Dal
{
    public class 入退社情報Dao : BaseAdoDao
    {
        private string m_requestTime;
        private string m_displayTime;

        public int Insert(入退社情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param20 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
                DbParameter param1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分);
                DbParameter param2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日);
                DbParameter param3 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項);
                DbParameter param4 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日);
                DbParameter param5 = _daoHelper.CreateParameter("@退社特記事項", obj.退社特記事項);
                DbParameter param6 = _daoHelper.CreateParameter("@退職理由", obj.退職理由);
                DbParameter param7 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.sp_Insert入退社情報, CommandType.StoredProcedure);
                command.Parameters.Add(param20);
                command.Parameters.Add(param1);
                command.Parameters.Add(param2);
                command.Parameters.Add(param3);
                command.Parameters.Add(param4);
                command.Parameters.Add(param5);
                command.Parameters.Add(param6);
                command.Parameters.Add(param7);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "INSERT", "Insert_HumanEnterInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public List<入退社情報> SelectAll()
        {
            DbCommand commands = _daoHelper.CreateCommand(CommandNameManager.sp_SelectAll入退社情報, CommandType.StoredProcedure);
            return _businessObjectHelper.FillToList<入退社情報>(_daoHelper.Query(commands));
        }

        public DataTable SelectAllTable()
        {
            DbCommand commands = _daoHelper.CreateCommand(CommandNameManager.sp_SelectAll入退社情報, CommandType.StoredProcedure);
            return _daoHelper.Query(commands);
        }

        public List<入退社情報> SelectPartial(String 社員ID)
        {
            try
            {
                DbCommand commands = _daoHelper.CreateCommand(CommandNameManager.sp_Select入退社情報_Partial_39, CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                commands.Parameters.Add(para);
                return _businessObjectHelper.FillToList<入退社情報>(_daoHelper.Query(commands));

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }


        public int Update(入退社情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param20 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int16);
                DbParameter param0 = _daoHelper.CreateParameter("@ＩＤ", obj.ＩＤ, DbType.Int32);
                DbParameter param1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分, DbType.Int32);
                DbParameter param2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日, DbType.DateTime);
                DbParameter param3 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項, DbType.String);
                DbParameter param4 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日, DbType.DateTime);
                DbParameter param5 = _daoHelper.CreateParameter("@退社特記事項", obj.退社特記事項, DbType.String);
                DbParameter param6 = _daoHelper.CreateParameter("@退職理由", obj.退職理由, DbType.Int32);
                DbParameter param7 = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);
                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Update_HumanEnterInfo, CommandType.StoredProcedure, param0, param20, param1, param2, param3, param4, param5, param6, param7);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "UPDATE", "Update_HumanEnterInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int Delete(int id)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param0 = _daoHelper.CreateParameter("@ＩＤ", id, DbType.Int32);

                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.Delete_HumanEnterInfo, CommandType.StoredProcedure, param0);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "DELETE", "Delete_HumanEnterInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }

        public int Insert_2(入退社情報 obj)
        {
            int i = 0;
            try
            {
                m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DbParameter param20 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
                DbParameter param1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分_1);
                DbParameter param2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日_1);
                DbParameter param3 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項);
                DbParameter param4 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日_1);
                DbParameter param5 = _daoHelper.CreateParameter("@退社特記事項", obj.退社特記事項);
                DbParameter param6 = _daoHelper.CreateParameter("@退職理由", obj.退職理由_1);
                DbParameter param7 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
                DbCommand command = _daoHelper.CreateCommand(CommandNameManager.sp_Insert入退社情報, CommandType.StoredProcedure);
                command.Parameters.Add(param20);
                command.Parameters.Add(param1);
                command.Parameters.Add(param2);
                command.Parameters.Add(param3);
                command.Parameters.Add(param4);
                command.Parameters.Add(param5);
                command.Parameters.Add(param6);
                command.Parameters.Add(param7);
                i = _daoHelper.Execute(command);
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteLog("", "", "INSERT", "Insert_HumanEnterInfo", m_requestTime, m_displayTime);
            }
            catch (Exception ex)
            {
                m_displayTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                ExportFile.WriteErr("", "", "SELECT", ex.Message, m_requestTime, m_displayTime);
            }
            return i;
        }
        #region phuong

        public DataTable Get入退社情報By社員ID(Int32 社員ID)
        {

            DbParameter dbParam1 = _daoHelper.CreateParameter("@社員ID", 社員ID, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_StaffEnterInput_Get_Phuong, CommandType.StoredProcedure, dbParam1);
            return _daoHelper.Query(dbcommand);

        }
        public DataTable Get入退社情報ByID(Int32 ID)
        {

            DbParameter dbParam1 = _daoHelper.CreateParameter("@ID", ID, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_StaffEnterInput_GetById_Phuong, CommandType.StoredProcedure, dbParam1);
            return _daoHelper.Query(dbcommand);

        }
        public void Insert入退社情報(入退社情報 obj)
        {
            DbParameter dbParam1 = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);
            DbParameter dbParam2 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int32);
            DbParameter dbParam3 = _daoHelper.CreateParameter("@採用区分 ", obj.採用区分, DbType.Int32);
            DbParameter dbParam4 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日, DbType.DateTime);
            DbParameter dbParam5 = _daoHelper.CreateParameter("@入社特記事項", (obj.入社特記事項 == "") ? null : obj.入社特記事項, DbType.String);
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DbParameter dbParam6 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日, DbType.DateTime);

            DbParameter dbParam7 = _daoHelper.CreateParameter("@退社特記事項", (obj.退社特記事項 == "") ? null : obj.退社特記事項, DbType.String);
            DbParameter dbParam8 = _daoHelper.CreateParameter("@退職理由", obj.退職理由1, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_StaffEnterInput_Insert_Phuong, CommandType.StoredProcedure,
       dbParam1, dbParam2, dbParam3, dbParam4, dbParam5, dbParam6, dbParam7, dbParam8);
            _daoHelper.Execute(dbcommand);

        }
        public void Update入退社情報(入退社情報 obj)
        {
            DbParameter dbParam1 = _daoHelper.CreateParameter("@ID", obj.ＩＤ, DbType.Int32);
            DbParameter dbParam2 = _daoHelper.CreateParameter("@採用区分 ", obj.採用区分, DbType.Int32);
            DbParameter dbParam3 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日, DbType.DateTime);
            DbParameter dbParam4 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項, DbType.String);
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DbParameter dbParam5 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日, DbType.DateTime);
            DbParameter dbParam6 = _daoHelper.CreateParameter("@退社特記事項", obj.退社特記事項, DbType.String);
            DbParameter dbParam7 = _daoHelper.CreateParameter("@退職理由", obj.退職理由1, DbType.Int32);
            DbCommand dbcommand = _daoHelper.CreateCommand(CommandNameManager.sp_frmJ_StaffEnterInput_Update_Phuong, CommandType.StoredProcedure,
     dbParam1, dbParam2, dbParam3, dbParam4, dbParam5, dbParam6, dbParam7);
            _daoHelper.Query(dbcommand);

        }

        #endregion

        #region Hunglt
        public void UpdateInfo入退社情報(入退社情報 obj)
        {
            DbParameter dbParam廃止区分 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分, DbType.Int32);
            DbParameter dbParam入社年月日 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日, DbType.DateTime);
            DbParameter dbParam入社特記事項 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項, DbType.String);
            DbParameter param社員ID = _daoHelper.CreateParameter("@社員ID", obj.社員ID, DbType.Int32);

            DbCommand dbcommand = _daoHelper.CreateCommand("sp_update_入退社情報_FormJ_Hunglt", CommandType.StoredProcedure, 
                dbParam廃止区分, dbParam入社年月日, dbParam入社特記事項, param社員ID);
            _daoHelper.Execute(dbcommand);
        }
        #endregion

        #region Hoat
        public DataTable SelectPartialTable(String 社員ID)
        {
            try
            {
                DbCommand commands = _daoHelper.CreateCommand(CommandNameManager.sp_Select入退社情報_Partial_39, CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                commands.Parameters.Add(para);
                DataTable dt = _daoHelper.Query(commands);
                return dt;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Coder: Ha Van Hoat
        /// Function: Lay du lieu tu bang 入退社情報
        /// Date: 19/03/2012
        /// </summary>
        /// <param name="社員ID"></param>
        /// <returns></returns>
        public DataTable ShowDataPageLoadFirtInsertMode(string 社員ID)
        {
            try
            {
                DbCommand commands = _daoHelper.CreateCommand("sp_Select入退社情報_Partial_Sort_入社年月日_Desc_39_Hoat", CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                commands.Parameters.Add(para);
                DataTable dt = _daoHelper.Query(commands);
                return dt;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Coder: Ha Van Hoat
        /// Function: Lay du lieu tu bang 入退社情報 sau khi Insert thanh cong
        /// </summary>
        /// <param name="社員ID"></param>
        /// <returns></returns>
        public DataTable ShowDataPageLoadAfterInsertMode(string 社員ID)
        {
            try
            {
                DbCommand commands = _daoHelper.CreateCommand("sp_Select入退社情報_Partial_Sort_ID_Desc_39_Hoat", CommandType.StoredProcedure);
                DbParameter para = _daoHelper.CreateParameter("@社員ID", 社員ID);
                commands.Parameters.Add(para);
                DataTable dt = _daoHelper.Query(commands);
                return dt;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public DataTable SelectPartialTable(string _社員ID, string _ID)
        {
            try
            {
                DbCommand commands = _daoHelper.CreateCommand("sp_Select入退社情報_PartialWith_社員ID_ID_39_Hoat", CommandType.StoredProcedure);
                DbParameter para1 = _daoHelper.CreateParameter("@社員ID", _社員ID);
                DbParameter para2 = _daoHelper.CreateParameter("@ID", _ID);
                commands.Parameters.Add(para1);
                commands.Parameters.Add(para2);
                DataTable dt = _daoHelper.Query(commands);
                return dt;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        public int Update入退社情報_Partial(入退社情報 obj, int ID)
        {
            int i = 0;
            try
            {
                DbParameter param7 = _daoHelper.CreateParameter("@ID", ID);
                DbParameter param1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分_1);
                DbParameter param2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日_1);
                DbParameter param3 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項);
                DbParameter param4 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日_1);
                DbParameter param5 = _daoHelper.CreateParameter("@退社特記事項", obj.退社特記事項);
                DbParameter param6 = _daoHelper.CreateParameter("@退職理由", obj.退職理由_1);
                DbCommand command = _daoHelper.CreateCommand("sp_Update入退社情報_Partial_39_Hoat", CommandType.StoredProcedure);
                
                command.Parameters.Add(param7);
                command.Parameters.Add(param1);
                command.Parameters.Add(param2);
                command.Parameters.Add(param3);
                command.Parameters.Add(param4);
                command.Parameters.Add(param5);
                command.Parameters.Add(param6);
                
                i = _daoHelper.Execute(command);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return i;
        }

        public int sp_Insert入退社情報_39(入退社情報 obj, out int ID)
        {
            int i = 0;
            ID = 0;
            m_requestTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            DbParameter param20 = _daoHelper.CreateParameter("@廃止区分", obj.廃止区分);
            DbParameter param1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分_1);
            DbParameter param2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日_1);
            DbParameter param3 = _daoHelper.CreateParameter("@入社特記事項", obj.入社特記事項);
            DbParameter param4 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日_1);
            DbParameter param5 = _daoHelper.CreateParameter("@退社特記事項", obj.退社特記事項);
            DbParameter param6 = _daoHelper.CreateParameter("@退職理由", obj.退職理由_1);
            DbParameter param7 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            DbParameter param8 = _daoHelper.CreateParameter("@ID", 0);
            param8.Direction = ParameterDirection.Output;

            DbCommand command = _daoHelper.CreateCommand("sp_Insert入退社情報_39_Hoat_2", CommandType.StoredProcedure);
            command.Parameters.Add(param20);
            command.Parameters.Add(param1);
            command.Parameters.Add(param2);
            command.Parameters.Add(param3);
            command.Parameters.Add(param4);
            command.Parameters.Add(param5);
            command.Parameters.Add(param6);
            command.Parameters.Add(param7);
            command.Parameters.Add(param8);

            i = _daoHelper.Execute(command);

            ID = Int32.Parse(command.Parameters["@ID"].Value.ToString());
            return i;
        }

        /// <summary>
        /// Coder: Van Hoat
        /// Function: Kiem tra khong the co 2 dong trung 
        /// 採用区分,入社年月日,退社年月日 ung voi 社員ID trong bang 
        /// Date: 01.03.2012
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool checkSame採用区分_入社年月日_退社年月日_Insert(入退社情報 obj, int intCase)
        {
            bool flag = false;
            
            DbParameter para1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分_1);
            DbParameter para2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日_1);
            DbParameter para3 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日_1);
            DbParameter para4 = _daoHelper.CreateParameter("@退職理由", obj.退職理由_1);
            DbParameter para5 = _daoHelper.CreateParameter("@社員ID", obj.社員ID);
            DbParameter para6 = _daoHelper.CreateParameter("@Case", intCase);

            DbCommand command = _daoHelper.CreateCommand("checkSame採用区分_入社年月日_退社年月日_Insert_39_Vh", CommandType.StoredProcedure, para1, para2, para3, para4, para5, para6);
            DataTable dt = _daoHelper.Query(command);
            
            if (dt.Rows.Count > 0)
                flag = true;

            return flag;
        }

        public bool checkExists採用区分_入社年月日_退社年月日_Update(入退社情報 obj, int idCurrent)
        {
            bool flag = false;

            DbParameter para1 = _daoHelper.CreateParameter("@採用区分", obj.採用区分_1);
            DbParameter para2 = _daoHelper.CreateParameter("@入社年月日", obj.入社年月日_1);
            DbParameter para3 = _daoHelper.CreateParameter("@退社年月日", obj.退社年月日_1);
            DbParameter para4 = _daoHelper.CreateParameter("@退職理由", obj.退職理由_1);
            DbParameter para5 = _daoHelper.CreateParameter("@ID", idCurrent);


            DbCommand command = _daoHelper.CreateCommand("checkExists採用区分_入社年月日_退社年月日_Update_39_Vh", CommandType.StoredProcedure, para1, para2, para3, para4, para5);
            DataTable dt = _daoHelper.Query(command);

            if (dt.Rows.Count > 0)
                flag = true;

            return flag;
        }

        #endregion
    }
}
